package cn.the.angry.tests;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.*;

public class JsonTest
{
	public static void main(final String args[]) throws JSONException
	{
		boolean[] boolArray = new boolean[]{true,false,true};
        JSONArray jsonArray1 = new JSONArray( boolArray );
        System.out.println( jsonArray1 );
          
        List list = new ArrayList();      
        list.add( "first" );      
        list.add( "second" );      
        JSONArray jsonArray2 = new JSONArray( list );      
        System.out.println( jsonArray2 ); 

        JSONArray jsonArray3 = new JSONArray( "['json','is','easy']" );      
        System.out.println( jsonArray3 );
        
        Map map1 = new HashMap();      
        map1.put( "name", "json" );      
        map1.put( "bool", Boolean.TRUE );
        map1.put( "int", new Integer(1) );      
        map1.put( "arr", new String[]{"a","b"} );      
        map1.put( "func", "function(i){ return this.arr[i]; }" );    
        map1.put( "array", jsonArray3);
        JSONObject jsonObject1 = new JSONObject( map1 );      
        System.out.println( jsonObject1 );
        
        JSONObject jsonObject2=new JSONObject(jsonObject1.toString());
        System.out.println("name : "+jsonObject2.getString("name"));
        System.out.println("bool : "+jsonObject2.getBoolean("bool"));
        System.out.println("int : "+jsonObject2.getInt("int"));
        System.out.println("arr : "+jsonObject2.get("arr"));
        System.out.println("func : "+jsonObject2.getString("func"));
        
        System.out.println("array : "+jsonObject2.getJSONArray("array"));
	}
}
